<?php
class post_commet { 
    var $pc_id;
    var $pc_p_id;
    var $pc_desc;
    var $pc_date;
    var $pc_u_id;
    var $pc_status;


    function Delete(){
        
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $q = " select pc_status from post_commet where pc_id ='".$this->pc_id."' " ;
        $rse = $DB->ObtenerData($q);   
        
        if($rse[0]["pc_status"]==0){
            $this->pc_status = 1;
        }else{
            $this->pc_status = 0;
        }
        
        $query = " UPDATE estado SET
                     pc_status='".$this->pc_status."'
                     where pc_id ='".$this->pc_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function Update(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function GetData(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
         
        $query = " Select * from post_commet where pc_id ='".$this->pc_id."' ";
        $rs = $DB->ObtenerData($query, "post_commet" );

        $this->pc_id = $rs[0]["pc_id"];
        $this->pc_p_id = $rs[0]["pc_p_id"];
        $this->pc_desc = $rs[0]["pc_desc"];
        $this->pc_date = $rs[0]["pc_date"];
        $this->pc_u_id = $rs[0]["pc_u_id"];
        $this->pc_status = $rs[0]["pc_status"];

        $DB->DesconectarBD();        
    }

    function Save(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $query = " INSERT INTO post_commet (
                     pc_id, pc_p_id, pc_desc, pc_date, pc_u_id, pc_status)
                    VALUES (NULL, '$this->pc_p_id', '$this->pc_desc', '$this->pc_date', '$this->pc_u_id', '$this->pc_status');" ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;        
    }
    
    function GetList($vals = false, $orderby = false, $lim= false){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        if ($_REQUEST["seccion"] == "postcommet" ) { //modulo post_commet
        
            if(!isset($_REQUEST["li"])){
                $li = 0;
            }else{
                $li = $_REQUEST["li"];
            }               

            if(isset($_REQUEST["page"])){
                $li = ($_REQUEST["page"]* $_SESSION['PREF']['LIST_LIMIT'])- $_SESSION['PREF']['LIST_LIMIT'];
            }

            if(!$vals){
                $vals = " * ";            
            }

            if(!$lim){
                $limit ="LIMIT ".$li.", ".$_SESSION['PREF']['LIST_LIMIT']." ";
            }

            if($orderby){            
                $order =" ORDER BY $orderby ";
            }else{
                $order =" ORDER BY pc_status desc, pc_desc asc ";
            }

            if(isset($_REQUEST["estado"]) && $_REQUEST["estado"] <> 99 ){ 
                $where .= " and pc_status = ".$_REQUEST["estado"]."  ";
            }   

            if($_REQUEST["filtro"]){
                $query = " Select $vals from post_commet where pc_desc like '%".$_REQUEST["filtro"]."%' $where
                                $order  $limit ";
            }else{
                $query = " Select $vals from post_commet where 1=1 $where   $order  $limit   ";
            }
            
        } else {  //desde fuera del MODULO POST_COMMET
            
             $query = " Select $vals from post_commet where pc_status = 1 $where  ";
            
        }
        
        $rs = $DB->ObtenerData($query, "post_commet");

        if (trim($vals) != "count(*)"){

            foreach ($rs as $key => $val) {
                $p = new post_commet();
                $p->set_pc_id($val["pc_id"]);
                $p->set_pc_p_id($val["pc_p_id"]);
                $p->set_pc_desc($val["pc_desc"]);
                $p->set_pc_date($val["pc_date"]);
                $p->set_pc_u_id($val["pc_u_id"]);
                $p->set_pc_status($val["pc_status"]);
                $rs2[] = $p;
            }

            $rs = $rs2;

            include_once 'recursos/funciones.php';
            $e = getEstado();        
            if(is_array($rs)){
                foreach ($rs as $key => $value) {
                    if ($value["pc_status"] == 1) {
                        $rs[$key]["pc_status"] = "<img src='images/png/estado_habilitado.png' />".$e[$value["pc_status"]];
                    } else {
                        $rs[$key]["pc_status"] = "<img src='images/png/estado_deshabilitado.png' />".$e[$value["pc_status"]];
                    }  
                }
            }
        }
        $DB->DesconectarBD();      
        return $rs;                
    }

    function get_pc_id(){
        return $this->pc_id;
    }
    function set_pc_id($val){
        $this->pc_id = $val;
    }

    function get_pc_p_id(){
        return $this->pc_p_id;
    }
    function set_pc_p_id($val){
        $this->pc_p_id = $val;
    }

    function get_pc_desc(){
        return $this->pc_desc;
    }
    function set_pc_desc($val){
        $this->pc_desc = $val;
    }

    function get_pc_date(){
        return $this->pc_date;
    }
    function set_pc_date($val){
        $this->pc_date = $val;
    }

    function get_pc_u_id(){
        return $this->pc_u_id;
    }
    function set_pc_u_id($val){
        $this->pc_u_id = $val;
    }

    function get_pc_status(){
        return $this->pc_status;
    }
    function set_pc_status($val){
        $this->pc_status = $val;
    }

}